package com.joolun.weixin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.joolun.system.domain.ScrmCustomerStaff;
import com.joolun.system.domain.vo.ScrmCustomerStaffCountVO;
import com.joolun.weixin.mapper.ScrmCustomerStaffMapper;
import com.joolun.weixin.service.IScrmCustomerStaffService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 企业微信客户-员工关联表 服务实现类
 *
 * @author xxh
 * @since 2021-12-22
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class ScrmCustomerStaffServiceImpl extends ServiceImpl<ScrmCustomerStaffMapper, ScrmCustomerStaff> implements IScrmCustomerStaffService {


    @Override
    public void delete(String id) {

        //校验参数
        ScrmCustomerStaff wxCustomerStaff = getById(id);

        //删除
        removeById(id);

    }


//    @Override
//    public void batchDelete(BatchDTO<String> dto) {
//
//        //校验参数
//        List<WxCustomerStaff> wxCustomerStaffList = new ArrayList<>();
//        Optional.ofNullable(dto.getIds()).orElse(new ArrayList<>()).forEach(id -> wxCustomerStaffList.add(getById(id)));
//
//        //删除
//        removeByIds(dto.getIds());
//    }


    @Override
    public ScrmCustomerStaff checkExists(String extCorpId, String extStaffId, String extCustomerId) {
        return getOne(new LambdaQueryWrapper<ScrmCustomerStaff>()
                .eq(ScrmCustomerStaff::getExtCorpId, extCorpId)
                .eq(ScrmCustomerStaff::getExtStaffId, extStaffId)
                .eq(ScrmCustomerStaff::getExtCustomerId, extCustomerId)
        );
    }

    @Override
    public ScrmCustomerStaff findHasDelete(String extCorpId, String extStaffId, String extCustomerId) {
        return baseMapper.findHasDelete(extCorpId, extStaffId, extCustomerId);
    }

    @Override
    public ScrmCustomerStaff findHasDelete(String id) {
        return baseMapper.findById(id);
    }

    @Override
    public List<ScrmCustomerStaffCountVO> countGroupByStaffExtId(String extCorpId) {
        return baseMapper.countGroupByStaffExtId(extCorpId);
    }
//
//    @Override
//    public List<WxCustomerStaff> listByCondition(ContactWayCountParamsVO paramsVO) {
//        return baseMapper.listByCondition(paramsVO);
//    }

    @Override
    public Integer countByDate(String extCorpId, String extStaffId, String state, Date date) {
        return baseMapper.countByDate(extCorpId, extStaffId, state, date);
    }

//    @Override
//    public WxCustomerStaffVO find(String exrCorpId, String customerId, String extStaffId) {
//
//        return translation(
//                getOne(new QueryWrapper<ScrmCustomerStaff>().lambda()
//                        .eq(ScrmCustomerStaff::getExtCorpId, exrCorpId)
//                        .eq(ScrmCustomerStaff::getCustomerId, customerId)
//                        .eq(ScrmCustomerStaff::getExtStaffId, extStaffId))
//        );
//    }


//    @Override
//    public List<WxCustomerPullNewStatisticsInfoVO> getPullNewStatisticsInfo(String extCorpId, Integer topNum, Date beginDate, Date endDate) {
//        return baseMapper.getPullNewStatisticsInfo(extCorpId, topNum, beginDate, endDate);
//    }

    @Override
    public long count(String extCorpId, Date begin, Date end, String staffExtId) {
        return baseMapper.countByExtCorpId(extCorpId, begin, end, staffExtId);
    }

//    private WxCustomerStaffVO translation(WxCustomerStaff wxCustomerStaff) {
//        WxCustomerStaffVO vo = new WxCustomerStaffVO();
//        BeanUtils.copyProperties(wxCustomerStaff, vo);
//
//        vo.setStaff(staffService.checkExists(vo.getExtStaffId(), vo.getExtCorpId()));
//        vo.setWxCustomer(customerService.checkExists(vo.getCustomerId()));
//
//        return vo;
//    }


    public int insertScrmCustomerStaff(ScrmCustomerStaff scrmCustomerStaff){
        return baseMapper.insert(scrmCustomerStaff);
    }


}
